import re

from classes import track


def get_template(track: track.FlacTrack):
    template = f"{track.title}\nRelease Date: {track.getReleaseDate().strftime('%d %B %Y')}\n\n#{track.genre}"
    if track.title.find("Silk") != -1:
        text = track.lyrics
        tracklist = f"\n\n"
        for line in text.splitlines():
            if line != "":
                line = re.sub(r"\d+\.", "", line)
                timecode = re.search(r"\[(\d\d:\d\d)\]", line)
                if timecode:
                    line = re.sub(r"\[(\d\d:\d\d)\]", "", line)
                    line = f"{timecode.group(1)} {line.rstrip().lstrip()}"
                tracklist += f"{line}\n"
        template += tracklist
    return template
